/**
 * 
 */
package com.suyx.job.service.area.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.suyx.job.entity.RoleInfo;
import com.suyx.job.entity.TuInfo;
import com.suyx.job.enums.SectEnums;
import com.suyx.job.utils.ScreenCapture;
import com.suyx.job.utils.SysStaticData;

/**
 * @author syx
 *
 */
@Service
public class GoToFc1AreaServiceImpl extends AbstractAreaService{

	public final static Map<String,String> options_x = new HashMap<>();  
	public final static Map<String,String> options_y = new HashMap<>();
	static {  
		options_x.put("0", "710 320");  
		options_x.put("1", "405 226");  
		options_x.put("2", "505 226");
		options_x.put("3", "605 226"); 
		options_x.put("4", "405 326");
		options_x.put("5", "505 326");
		options_x.put("6", "605 326");
		options_x.put("7", "405 426");
		options_x.put("8", "505 426");
		options_x.put("9", "605 426");
		
		options_y.put("0", "844 320");  
		options_y.put("1", "543 223");  
		options_y.put("2", "643 223");
		options_y.put("3", "743 223"); 
		options_y.put("4", "543 323");
		options_y.put("5", "643 323");
		options_y.put("6", "743 323");
		options_y.put("7", "543 423");
		options_y.put("8", "643 423");
		options_y.put("9", "743 423");
	} 
	@Override
	public boolean execute(String device, String path, String area) {
		try {
			String[] infos = SysStaticData.CS1.get("凤巢1").split("&");
			userCS1(device,infos);
			ScreenCapture.mouseClick(device, "1224 620");
			Thread.sleep(2 * 1000L);
			//点击地图
			ScreenCapture.mouseClick(device, "148 38");
			ScreenCapture.mouseClick(device, "708 430");
			//关闭地图
			ScreenCapture.mouseClick(device, "1081 83");
			Thread.sleep(26 * 1000L);		
			//到达北俱芦洲
			ScreenCapture.mouseClick(device, "718 306");
			Thread.sleep(2 * 1000L);
			ScreenCapture.mouseClick(device, "1209 355");
			Thread.sleep(2 * 1000L);
			
			//点击地图
			ScreenCapture.mouseClick(device, "148 38");
			ScreenCapture.mouseClick(device, "710 222");
			//关闭地图
			ScreenCapture.mouseClick(device, "1127 79");
			Thread.sleep(34 * 1000L);	
			// 到凤1
			ScreenCapture.mouseClick(device, "698 174");
			Thread.sleep(2 * 1000L);
			
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean support(String area) {
		return SectEnums.FC1.getCode().equals(area);
	}

	@Override
	public boolean goToPoint(RoleInfo roleInfo, String path, TuInfo tuInfo) {
		String device = roleInfo.getDevice();
		String area = tuInfo.getZuobiaoX()+" "+tuInfo.getZuobiaoY();
		try {
			Thread.sleep(2 * 1000L);
			ScreenCapture.mouseClick(device, "117 68");//打开地图
	        ScreenCapture.mouseClick(device, "430 120");// 选x坐标
	        String x = area.split(" ")[0];
	        String y = area.split(" ")[1];
	        input_x(device,x);
	        ScreenCapture.mouseClick(device, "705 426");
	        ScreenCapture.mouseClick(device, "558 112"); // 选y坐标
	        input_y(device, y);
	        ScreenCapture.mouseClick(device, "843 423");
	        ScreenCapture.mouseClick(device, "700 110");  // 前往
	        ScreenCapture.mouseClick(device, "1131 87"); //关闭地图
	        
	        startGoto(roleInfo,path,tuInfo);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	
	private  void input_x(String device,String x){
		for(int i =0;i<x.length();i++){
			char c = x.charAt(i);
			String x_zb = options_x.get(String.valueOf(c));
			ScreenCapture.mouseClick(device, x_zb);
		}
	}
	
	private void input_y(String device,String y){
		for(int i =0;i<y.length();i++){
			char c = y.charAt(i);
			String y_zb = options_y.get(String.valueOf(c));
			ScreenCapture.mouseClick(device, y_zb);
		}
	}
}
